
package com.epfresh.supplier.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.supplier.R;
import com.epfresh.supplier.entity.AuthStatus;
import com.epfresh.supplier.entity.CategoryNames;

import java.util.HashMap;
import java.util.Map;

import multitype.ItemViewBinder;
import multitype.OnRecyclerViewItemClickListener;

public class OrderAuthViewBinder
    extends ItemViewBinder<AuthStatus, OrderAuthViewBinder.ViewHolder> implements View.OnClickListener{


    Map<String ,String> mapAuth = new HashMap<>();
    Map<String ,Integer> mapAuthIcon = new HashMap<>();
    Map<String ,Integer> mapAuthIconUnable = new HashMap<>();


  
    /*  {
        "root.app.supplier.store" : true,
            "root.app.supplier.product.price_and_purchase" : true,
            "root.app.supplier.store.decoration" : true,
            "root.app.supplier.order.jmt" : true,
            "root.app.supplier.product.selling" : true,
            "root.app.supplier.standing_book" : true,
            "root.app.supplier.product.presell" : true,
            "root.app.supplier.employee" : true,
            "root.app.supplier.income" : true,
            "root.app.supplier.customer" : true,
            "root.app.supplier.order" : true,
            "root.app.supplier.buy" : true,
            "root.app.supplier.coupon" : true,
            "root.app.supplier.comment" : true,
            "root.app.supplier.push_message" : true
    }*/
    
     /* 我要买    root.app.supplier.buy
    店铺装修    root.app.supplier.store.decoration
    店铺管理    root.app.supplier.store
    消息推送    root.app.supplier.push_message
    员工管理    root.app.supplier.employee
    客户管理    root.app.supplier.customer
    我的收入    root.app.supplier.income
    我的台帐    root.app.supplier.standing_book
    评价       root.app.supplier.comment
    优惠券     root.app.supplier.coupon
    减免退     root.app.supplier.order.jmt
    变价/进货  root.app.supplier.product.price_and_purchase
    预售商品   root.app.supplier.product.presell
    现货商品   root.app.supplier.product.selling
    销售订单   root.app.supplier.order */


    {
        mapAuth.clear();
        mapAuthIcon.clear();
        mapAuthIconUnable.clear();
        //mapAuth.put("root.app.supplier.buy","我要买");
        mapAuth.put("root.app.supplier.store.decoration","店铺装修");
        mapAuth.put("root.app.supplier.store","店铺管理");
        mapAuth.put("root.app.supplier.push_message","消息推送");
        mapAuth.put("root.app.supplier.employee","员工管理");
        mapAuth.put("root.app.supplier.customer","客户管理");
        mapAuth.put("root.app.supplier.income","我的收入");
        mapAuth.put("root.app.supplier.standing_book","我的台账");
        mapAuth.put("root.app.supplier.comment","评价");
        mapAuth.put("root.app.supplier.coupon","优惠券");
        mapAuth.put("root.app.supplier.order.jmt","减免退");
        //mapAuth.put("root.app.supplier.product.price_and_purchase","变价/进货");
        mapAuth.put("root.app.supplier.joint.product","联营报价");
        mapAuth.put("root.app.supplier.product.purchase","进货");
        mapAuth.put("root.app.supplier.product.presell","预售商品");
        mapAuth.put("root.app.supplier.product.selling","现货商品");
        mapAuth.put("root.app.supplier.order","销售订单");
        
        //mapAuthIcon.put("root.app.supplier.buy",null);
        mapAuthIcon.put("root.app.supplier.store.decoration",R.mipmap.icon_home_decorate);
        mapAuthIcon.put("root.app.supplier.store",R.mipmap.icon_home_store_manage);
        mapAuthIcon.put("root.app.supplier.push_message",null);
        mapAuthIcon.put("root.app.supplier.employee",R.mipmap.icon_home_staff_manager);
        mapAuthIcon.put("root.app.supplier.customer",R.mipmap.icon_home_custom_manage);
        mapAuthIcon.put("root.app.supplier.income",R.mipmap.icon_home_income);
        mapAuthIcon.put("root.app.supplier.standing_book",R.mipmap.icon_home_stand_book);
        mapAuthIcon.put("root.app.supplier.comment",R.mipmap.icon_home_comment);
        mapAuthIcon.put("root.app.supplier.coupon",R.mipmap.icon_home_coupon);
        mapAuthIcon.put("root.app.supplier.order.jmt",R.mipmap.icon_home_halve);
        //mapAuthIcon.put("root.app.supplier.product.price_and_purchase",null);
        mapAuthIcon.put("root.app.supplier.joint.product",R.mipmap.icon_home_join_price);
        mapAuthIcon.put("root.app.supplier.product.purchase",R.mipmap.icon_home_stock);
        mapAuthIcon.put("root.app.supplier.product.presell",R.mipmap.icon_home_pre_commodit);
        mapAuthIcon.put("root.app.supplier.product.selling",R.mipmap.icon_home_cash_commodity);
        mapAuthIcon.put("root.app.supplier.order",R.mipmap.icon_home_sale_order);
        
        //mapAuthIconUnable.put("root.app.supplier.buy",null);
        mapAuthIconUnable.put("root.app.supplier.store.decoration",R.mipmap.icon_home_unable_decorate);
        mapAuthIconUnable.put("root.app.supplier.store",R.mipmap.icon_home_unable_store_manage);
        mapAuthIconUnable.put("root.app.supplier.push_message",null);
        mapAuthIconUnable.put("root.app.supplier.employee",R.mipmap.icon_home_unable_staff_manager);
        mapAuthIconUnable.put("root.app.supplier.customer",R.mipmap.icon_home_unable_custom_manage);
        mapAuthIconUnable.put("root.app.supplier.income",R.mipmap.icon_home_unable_income);
        mapAuthIconUnable.put("root.app.supplier.standing_book",R.mipmap.icon_home_unable_stand_book);
        mapAuthIconUnable.put("root.app.supplier.comment",R.mipmap.icon_home_unable_comment);
        mapAuthIconUnable.put("root.app.supplier.coupon",R.mipmap.icon_home_unable_coupon);
        mapAuthIconUnable.put("root.app.supplier.order.jmt",R.mipmap.icon_home_unable_halve);
        mapAuthIconUnable.put("root.app.supplier.product.price_and_purchase",null);
        mapAuthIconUnable.put("root.app.supplier.joint.product",R.mipmap.icon_home_unable_join_price);
        mapAuthIconUnable.put("root.app.supplier.product.purchase",R.mipmap.icon_home_unable_stock);
        mapAuthIconUnable.put("root.app.supplier.product.presell",R.mipmap.icon_home_unable_pre_commodit);
        mapAuthIconUnable.put("root.app.supplier.product.selling",R.mipmap.icon_home_unable_cash_commodity);
        mapAuthIconUnable.put("root.app.supplier.order",R.mipmap.icon_home_unable_sale_order);


    }



    OnRecyclerViewItemClickListener onRecyclerViewItemClickListener;

    public OnRecyclerViewItemClickListener getOnRecyclerViewItemClickListener() {
        return onRecyclerViewItemClickListener;
    }

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener onRecyclerViewItemClickListener) {
        this.onRecyclerViewItemClickListener = onRecyclerViewItemClickListener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_auth_status, parent, false);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull AuthStatus post) {

//        holder.itemView.setTag(R.id.item_key_position,-1);
//        holder.itemView.setTag(R.id.item_key_status,post);
//        holder.itemView.setOnClickListener(this);

//        ImageLoader.getInstance().displayImage(post.getIcon(),holder.ivCover);
        if (post.isEmpty()||post.getKey().equals("root.app.supplier.buy")||post.getKey().equals("root.app.supplier.sell")){
            holder.tvTitle.setVisibility(View.INVISIBLE);
            holder.ivCover.setVisibility(View.INVISIBLE);

            holder.itemView.setOnClickListener(null);
        }else {
            holder.tvTitle.setVisibility(View.VISIBLE);
            holder.ivCover.setVisibility(View.VISIBLE);
            String key = post.getKey();


            String s = mapAuth.get(key);

            Integer res = null;

            if (post.isAuth()) {

                res = mapAuthIcon.get(key);
            } else {
                res = mapAuthIconUnable.get(key);
            }
            Log.e("res",res+"___");
            Log.e("key",key+"___");

            Log.e("tvTitle",holder.tvTitle+"___");
            holder.tvTitle.setText(s);
            if (s.equals("联营报价")) {
                if (post.getUpdateJoinPrice() == 1) {
                    holder.img_tip.setVisibility(View.VISIBLE);
                }else {
                    holder.img_tip.setVisibility(View.GONE);
                }
            } else {
                holder.img_tip.setVisibility(View.GONE);
            }

            holder.ivCover.setImageResource(res);

            holder.itemView.setTag(R.id.item_key_position, getPosition(holder));
            holder.itemView.setTag(R.id.item_key_status, post);
            holder.itemView.setOnClickListener(this);
        }

    }

    @Override
    public void onClick(View v) {

        Object tag = v.getTag(R.id.item_key_position);
        if (tag != null && tag instanceof Integer){
            int position = (int) tag;
            Object o = v.getTag(R.id.item_key_status);

            if (onRecyclerViewItemClickListener != null && o instanceof AuthStatus){
                onRecyclerViewItemClickListener.onItemClick(v,position,o);
            }
        }
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView ivCover,img_tip;
        private TextView tvTitle;


        ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivCover = (ImageView) itemView.findViewById(R.id.iv_icon);
            img_tip = (ImageView) itemView.findViewById(R.id.img_tip);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);

        }


        void setData(@NonNull final AuthStatus post) {



        }
    }
}
